//
//  SDHttpRequestManagement.h
//  SKinDiary
//
//  Created by pcyang on 16/6/26.
//  Copyright © 2016年 tencent. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SDReachability.h"
#import "SDHTTPRequestOperation.h"



@interface SDFormPartInfo :NSObject

@property(nonatomic,strong) NSURL  *fileUrl;
@property(nonatomic,strong) NSString *partName;
@property(nonatomic,strong) NSString *fileName;
@property(nonatomic,strong) NSString *mimeType;

@end


typedef NS_ENUM( NSInteger,SDHttpRequestPriority )
{
    SDHttpRequestPriority_VeryLow		= -2,
    SDHttpRequestPriority_Low			= -1,
    SDHttpRequestPriority_Normal		= 0,
    SDHttpRequestPriority_High			= 1,
    SDHttpRequestPriority_VeryHigh		= 2,
    
    SDHttpRequestPriority_Immediately   = 3,    //Normally first 3 requests can start immediately, others must wait.
};

typedef NS_ENUM( NSInteger,SDHttpRequest_Errorcode )
{
    SDHttpRequest_Errorcode_None                = 0,
    SDHttpRequest_Errorcode_InvalidParameter   = -1000,
    SDHttpRequest_Errorcode_NoActiveNetwork    = -1001,
    SDHttpRequest_Errorcode_ResponseError      = -1002,
    SDHttpRequest_Errorcode_InParamError       = -1003
};

extern NSString* SDHttpRequest_ErrorDomain;
extern NSString* Notification_NetWorkStatusChanged;
extern NSString* kSDHttpRequest_ResponseCode;
extern NSString* kSDHttpRequest_ResponseInfo;

typedef SDHttpRequestPriority WYHttpRequestPriority;
typedef SDHttpRequest_Errorcode WYHttpRequest_Errorcode;

#define WYHttpRequestPriority_VeryLow       SDHttpRequestPriority_VeryLow
#define WYHttpRequestPriority_Low           SDHttpRequestPriority_Low
#define WYHttpRequestPriority_Normal        SDHttpRequestPriority_Normal
#define WYHttpRequestPriority_High          SDHttpRequestPriority_High
#define WYHttpRequestPriority_VeryHigh      SDHttpRequestPriority_VeryHigh
#define WYHttpRequestPriority_Immediately   SDHttpRequestPriority_Immediately

#define WYHttpRequest_Errorcode_None                SDHttpRequest_Errorcode_None
#define WYHttpRequest_Errorcode_InvalidParameter    SDHttpRequest_Errorcode_InvalidParameter
#define WYHttpRequest_Errorcode_NoActiveNetwork     SDHttpRequest_Errorcode_NoActiveNetwork
#define WYHttpRequest_Errorcode_ResponseError       SDHttpRequest_Errorcode_ResponseError

#define WYHttpRequest_ErrorDomain                   SDHttpRequest_ErrorDomain

@interface SDHttpRequestManagement : NSObject
DEF_SINGLETON;
+ (SDHttpRequestManagement*)sharedHttpRequestManagement;
- (NetworkStatus)currentNetworkStatus;
- (void)addHttpRequestOperation:(AFHTTPRequestOperation*)operation;
- (void)addOperation:(NSOperation*)operation;
- (void)addHttpRequest:(NSOperation*)operation withPriority:(SDHttpRequestPriority)priority;


+ (SDHTTPRequestOperation*)startHttpRequestWithURL:(NSString*)url
                                         jsonParser:(BOOL)jsonParser
                                     requestCookies:(NSDictionary*)requestCookies
                                           priority:(SDHttpRequestPriority)priority
                                  objectParserBlock:(id (^)(id data,NSError** error))block
                                    completionQueue:(dispatch_queue_t)completionQueue
                                         completion:(void (^)(id data, NSError *error))completion;

+ (SDHTTPRequestOperation*)startHttpRequestWithURL:(NSString*)url
                                         jsonParser:(BOOL)jsonParser
                                     requestCookies:(NSDictionary*)requestCookies
                                           priority:(SDHttpRequestPriority)priority
                                  objectParserBlock:(id (^)(id data,NSError** error))block
                                         completion:(void (^)(id data, NSError *error))completion;

+ (SDHTTPRequestOperation*)startHttpRequestAndParsingResultWithURL:(NSString*)url
                                                           priority:(SDHttpRequestPriority)priority
                                                     requestCookies:(NSDictionary*)requestCookies
                                                  objectParserBlock:(id (^)(id data,NSError** error))block
                                                         completion:(void (^)(id data, NSError *error))completion;

+ (SDHTTPRequestOperation*)startHttpPostRequestWithURL:(NSString*)url
                                              postValue:(NSDictionary*)postValue
                                         requestCookies:(NSDictionary*)requestCookies
                                             jsonParser:(BOOL)jsonParser
                                               priority:(SDHttpRequestPriority)priority
                                      objectParserBlock:(id (^)(id data,NSError** error))block
                                        completionQueue:(dispatch_queue_t)completionQueue
                                             completion:(void (^)(id data, NSError *error))completion;

+ (SDHTTPRequestOperation*)startHttpPostRequestWithURL:(NSString*)url
                                              postValue:(NSDictionary*)postValue
                                         requestCookies:(NSDictionary*)requestCookies
                                             jsonParser:(BOOL)jsonParser
                                               priority:(SDHttpRequestPriority)priority
                                      objectParserBlock:(id (^)(id data,NSError** error))block
                                             completion:(void (^)(id data, NSError *error))completion;


+ (SDHTTPRequestOperation*)startHttpPutRequestWithURL:(NSString*)url
                                            postValue:(NSDictionary*)postValue
                                       requestCookies:(NSDictionary*)requestCookies
                                           jsonParser:(BOOL)jsonParser
                                             priority:(WYHttpRequestPriority)priority
                                    objectParserBlock:(id (^)(id data,NSError** error))block
                                      completionQueue:(dispatch_queue_t)completionQueue
                                           completion:(void (^)(id data, NSError *error))completion;

+ (SDHTTPRequestOperation*)startRequestWithHttpMethod:(NSString*)httpMethod
                                                  url:(NSString*)url
                                            postValue:(NSDictionary*)postValue
                                       requestCookies:(NSDictionary*)requestCookies
                                           jsonParser:(BOOL)jsonParser
                                             priority:(WYHttpRequestPriority)priority
                                    objectParserBlock:(id (^)(id data,NSError** error))block
                                      completionQueue:(dispatch_queue_t)completionQueue
                                           completion:(void (^)(id data, NSError *error))completion;
@end

typedef SDHttpRequestManagement WYHttpRequestManagement;
